﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class carddata : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerEnterHandler, IPointerExitHandler
{
    public Card card;
    public int amount;
    private tooltip tooltp;
    private cardcontrol cardd;
    private cardbigimg img;
    public int slot;

    void Start()
    {
        cardd = GameObject.Find("cardmanager").GetComponent<cardcontrol>();
        tooltp = GameObject.Find("cardmanager").GetComponent<tooltip>();
        img = GameObject.Find("cardbigimg").GetComponent<cardbigimg>();
    }

    public void OnBeginDrag(PointerEventData eventData)
    {
        if (card != null)
        {
            this.transform.SetParent(this.transform.parent.parent);
            this.transform.position = eventData.position;
            GetComponent<CanvasGroup>().blocksRaycasts = false;
        }
    }

    public void OnDrag(PointerEventData eventData)
    {
        if (card != null)
        {
            this.transform.position = eventData.position;
        }
    }

    public void OnEndDrag(PointerEventData eventData)
    {
        this.transform.SetParent(cardd.slots[slot].transform);
        this.transform.position = cardd.slots[slot].transform.position;
        GetComponent<CanvasGroup>().blocksRaycasts = true;
    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        tooltp.Activate(card);
        img.Activate(card);
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        tooltp.Deactivate();
        img.Deactivate();
    }

}

